//
//  UserfulOneCell.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/3/20.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "UserfulOneCell.h"

#import "KSDatePicker.h"
@implementation UserfulOneCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
      
        _firstLab= [[UILabel alloc] init];
        _firstLab.text = @"来访日期 :";
        _firstLab.font = [UIFont systemFontOfSize:14];
        _firstLab.textColor =[UIColor blackColor];
        [self addSubview:_firstLab];
        [_firstLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(90, 18));
            make.top.equalTo(self.mas_top).offset(15);
            make.left.equalTo(self.mas_left).offset(8);
        }];
        
        _timeLab= [[UILabel alloc] init];
        _timeLab.font = [UIFont systemFontOfSize:14];
        _timeLab.layer.cornerRadius =5;
        _timeLab.layer.borderWidth = 0.5;
        _timeLab.layer.borderColor = [UIColor grayColor].CGColor;
        _timeLab.textColor =[UIColor blackColor];
        [self addSubview:_timeLab];
        [_timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(180, 30));
            make.top.equalTo(self.mas_top).offset(10);
            make.left.equalTo(self.mas_left).offset(105);
            
        }];

        _riLBtn= [UIButton buttonWithType:UIButtonTypeCustom];
        [_riLBtn setBackgroundImage:[UIImage imageNamed:@"btnRiLi"] forState:0];
        [_riLBtn addTarget:self action:@selector(riLiBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:_riLBtn];
        [_riLBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(30, 20));
            make.right.equalTo(_timeLab.mas_right).offset(-5);
            make.top.equalTo(_timeLab.mas_top).offset(5);
        }];


    }
    return self;
}

-(void)riLiBtnClick:(UIButton *)sender
{
    NSLog(@"日历的 tag 值====== %ld",sender.tag);
    KSDatePicker* picker = [[KSDatePicker alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width - 40, 300)];
    picker.appearance.radius = 5;
    
    //设置回调
    picker.appearance.resultCallBack = ^void(KSDatePicker* datePicker,NSDate* currentDate,KSDatePickerButtonType buttonType){
        
        if (buttonType == KSDatePickerButtonCommit) {
            
            NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
            [formatter setDateFormat:@"yyyy-MM-dd"];
            
            _timeLab.text = [formatter stringFromDate:currentDate];
            NSLog(@"日历是多少=======%@",_timeLab.text);
         [self.delegate riLiBtnClick:sender withLab:_timeLab.text];
        }
    };
    // 显示
    [picker show];
    
   
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
